package com.yingdong.logic.service;

import java.io.File;
import java.lang.reflect.Field;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Service;

import com.yingdong.annotation.AutoInvoke;
import com.yingdong.tools.Excel2007Reader;

@Service
public class DataService {
	static Log logger = LogFactory.getLog(DataService.class);

	@AutoInvoke
	public static void init() throws Exception {
		File f = new File("excel");
		File[] files = f.listFiles();
		for (File file : files) {
			if (file.isFile() && file.getName().contains(".xlsx")) {
				String fileName = file.getName().split("\\.")[0];
				Class claz = Class.forName("com.yingdong.excel." + fileName);
				List list = Excel2007Reader.readDataFromFileJava("excel/" + fileName + ".xlsx", claz);
				Field field=claz.getField("data");
				field.set(null, list);
			}
		}
		logger.info("DataService加载完毕");
	}
}
